---------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/TJRyan/Dropbox/Facebook Experiments/Replication files/import-
> main.log
  log type:  text
 opened on:  31 Aug 2015, 11:18:13

. do "/Users/TJRyan/Dropbox/Facebook Experiments/Replication files/import-main.do
> "

. 
. clear all

. set more off

. insheet using "Ad report.csv"
(4 vars, 19458 obs)

. 
. collapse (sum) impressions clicks, by(adname)

. 
. save "collapsed.dta", replace
file collapsed.dta saved

. 
. clear all

. 
. insheet using "condinfo.csv"
(13 vars, 846 obs)

. 
. save "condinfo.dta", replace
file condinfo.dta saved

. 
. clear all

. 
. use "collapsed.dta"

. 
. merge 1:1 adname using "condinfo.dta", keepus(title body link regions relations
> hip gender ///
> agemin broadcategoryclusters image)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                               846  (_merge==3)
    -----------------------------------------

. 
. drop _merge

. 
. gen conda = 0

. gen condb = 0

. gen condc = 0

. gen condd = 0

. gen conde = 0

. gen condf = 0

. gen condg = 0

. gen condh = 0

. gen condi = 0

. gen condj = 0

. gen condk = 0

. gen condl = 0

. 
. replace conda = 1 if regexm(link, "coa")
(70 real changes made)

. replace condb = 1 if regexm(link, "cob")
(71 real changes made)

. replace condc = 1 if regexm(link, "coc")
(71 real changes made)

. replace condd = 1 if regexm(link, "cod")
(70 real changes made)

. replace conde = 1 if regexm(link, "coe")
(71 real changes made)

. replace condf = 1 if regexm(link, "cof")
(71 real changes made)

. replace condg = 1 if regexm(link, "cog")
(70 real changes made)

. replace condh = 1 if regexm(link, "coh")
(70 real changes made)

. replace condi = 1 if regexm(link, "coi")
(70 real changes made)

. replace condj = 1 if regexm(link, "coj")
(70 real changes made)

. replace condk = 1 if regexm(link, "cok")
(71 real changes made)

. replace condl = 1 if regexm(link, "col")
(71 real changes made)

. 
. gen cond = ""
(846 missing values generated)

. replace cond = "a" if conda==1
(70 real changes made)

. replace cond = "b" if condb==1
(71 real changes made)

. replace cond = "c" if condc==1
(71 real changes made)

. replace cond = "d" if condd==1
(70 real changes made)

. replace cond = "e" if conde==1
(71 real changes made)

. replace cond = "f" if condf==1
(71 real changes made)

. replace cond = "g" if condg==1
(70 real changes made)

. replace cond = "h" if condh==1
(70 real changes made)

. replace cond = "i" if condi==1
(70 real changes made)

. replace cond = "j" if condj==1
(70 real changes made)

. replace cond = "k" if condk==1
(71 real changes made)

. replace cond = "l" if condl==1
(71 real changes made)

. 
. * Factor variables
. gen gaffe=0

. replace gaffe = 1 if regexm(title, "Oops")
(423 real changes made)

. 
. gen romneyneg = 0

. replace romneyneg = 1 if regexm(body, "Romney")
(423 real changes made)

. 
. gen lib = 0

. replace lib = 1 if regexm(broadcategoryclusters, "Liberal")
(282 real changes made)

. 
. gen cons = 0

. replace cons = 1 if regexm(broadcategoryclusters, "Conservative")
(282 real changes made)

. 
. gen partisan = 0

. replace partisan = 1 if lib==1 | cons==1
(564 real changes made)

. 
. gen sports = 0

. replace sports = 1 if regexm(broadcategoryclusters, "Music")
(141 real changes made)

. 
. gen music = 0

. replace music = 1 if regexm(broadcategoryclusters, "Sports")
(141 real changes made)

. 
. gen ind = 0

. replace ind = 1 if sports==1 | music==1
(282 real changes made)

. 
. gen ctp = (clicks / impressions) * 100 // click-through percentage

. gen ctpr = ctp * 100  // Rescaled click-through percentage

. 
. gen geog = 0

. replace geog = 1 if regexm(regions, "Texas")
(424 real changes made)

. 
. gen female = 0

. replace female = 1 if regexm(gender, "Women")
(422 real changes made)

. 
. gen relat = 0

. replace relat = 1 if regexm(relationship, "Single")
(423 real changes made)

. 
. rename agemin age

. 
. gen age2 = (age - 18) / 46 // scale 0-1

. 
. gen ownad = .
(846 missing values generated)

. 
. replace ownad = 1 if cond=="c" | cond=="d" | cond=="e" | cond=="f"
(283 real changes made)

. replace ownad = 0 if cond=="a" | cond=="b" | cond=="g" | cond=="h"
(281 real changes made)

. 
. * Restructuring of DV for one table in the SI.
. gen ctpr2 = ctpr

. replace ctpr2 = . if ctpr<=0
(427 real changes made, 427 to missing)

. gen ctpr3 = ctpr

. replace ctpr3 = 0 if ctpr<=0
(0 real changes made)

. 
. save "working.dta", replace
file working.dta saved

. 
end of do-file

. log close
      name:  <unnamed>
       log:  /Users/TJRyan/Dropbox/Facebook Experiments/Replication files/import-
> main.log
  log type:  text
 closed on:  31 Aug 2015, 11:18:20
---------------------------------------------------------------------------------
